home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / System / StyleWriter Page Monitor GX / Source / PageMon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-08  |  2.1 KB  |  104 lines  |  [TEXT/MMCC]

  1. /***
  2.  * PageMon.c
  3.  *
  4.  *  This file contains the coor overrides for the messageing that is needed to implement
  5.  *  the page monitor extension
  6.  *
  7.  *  Gordon Watts March, 1994
  8.  *
  9.  ***/
  10. #include "Headers.h"
  11.  
  12. #include "PageMon.h"
  13. #include "Exceptions.h"
  14. #include "logIO.h"
  15.  
  16. /**
  17.  ** Instance vars for this job.  These are kept round during the imaging of the job
  18.  **/
  19.  
  20. typedef struct {
  21.     long    pagesImaged;
  22. } pageMonInstanceVars, *pageMonInstanceVarsPtr, **pageMonInstanceVarsHdl;
  23.  
  24. /**
  25.  * PageMonImageJob
  26.  *
  27.  *  We count the number of pages here, and write them out to a file
  28.  *
  29.  **/
  30. OSErr PageMonImageJob ( gxSpoolFile thePrintFile, long *closeOptions)
  31. {
  32.     OSErr                            anErr;
  33.     pageMonInstanceVarsHdl    theVars;
  34.  
  35.     /**
  36.      ** Allocate some instance vars for this job...
  37.      **/
  38.     
  39.     theVars = (pageMonInstanceVarsHdl) NewHandle (sizeof (pageMonInstanceVars));
  40.     (*theVars) -> pagesImaged = 0;
  41.  
  42.     SetMessageHandlerInstanceContext (theVars);
  43.  
  44.     /**
  45.      ** Now, just send on the Image Job message and get it all over with!
  46.      **/
  47.  
  48.     anErr = Forward_GXImageJob (thePrintFile, closeOptions);
  49.     
  50.     /**
  51.      ** Now that the job has been imaged (noErr or otherwise return), write out the
  52.      ** page count, deallocate the instance var memory, and reset the instance
  53.      ** handle so GX doesn't get confused.
  54.      **/
  55.     
  56.     WriteToLog ((*theVars) -> pagesImaged);
  57.  
  58.     SetMessageHandlerInstanceContext (0L);
  59.     DisposHandle ((Handle) theVars);
  60.  
  61.     /**
  62.      ** Done!
  63.      **/
  64.  
  65.     return anErr;
  66. }
  67.  
  68. /**
  69.  * PageMonImagePage
  70.  *
  71.  *  Image a single page.  For us, we just increment the count of pages after doing the default
  72.  *  behavior!
  73.  *
  74.  **/
  75. OSErr PageMonImagePage (gxSpoolFile theSpoolFile, long pageNumber, gxFormat theFormat,
  76.                                     void *imageData)
  77. {
  78.     OSErr    theErr;
  79.     pageMonInstanceVarsHdl    theVars;
  80.  
  81.     /**
  82.      ** First, image the page
  83.      **/
  84.     
  85.     theErr = Forward_GXImagePage (theSpoolFile, pageNumber, theFormat, imageData);
  86.     nrequire (theErr, FailedGXImagePage);
  87.  
  88.     /**
  89.      ** Retreive (sp?) our instance variables
  90.      **/
  91.  
  92.     theVars = GetMessageHandlerInstanceContext();
  93.     require (theVars != 0, FailedGetVars);
  94.  
  95.     (*theVars) -> pagesImaged += 1;
  96.         
  97.     /**
  98.      ** Done!
  99.      **/
  100.  
  101. FailedGetVars:
  102. FailedGXImagePage:
  103.     return theErr;
  104. }